<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">
    姓：<input type="text" v-model="xing"><br>
    名：<input type="text" v-model="ming"><br>
    <p>姓名：{{xingming}}</p>
    修改名字：<input type="text" v-model="name">
    <button @click="changename">修改姓名</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        xing: '刘',
        ming: '玄德',
        name: ''
      },
      computed: {
        // 简写，只求值不反改
        // xingming() {
        //   return this.xing + this.ming
        // }

        // 完整写法
        xingming: {
          get() {
            return this.xing + this.ming
          },
          set(value) {
            this.xing = value.slice(0, 1)
            this.ming = value.slice(1)

          }
        }
      },
      methods: {
        changename() {
          this.xingming = this.name
        }
      }
    })
  </script>
</body>

</html>